package com.dazhewan.project.component;

import com.dazhewan.project.properties.ContainerSize;
import com.dazhewan.project.properties.CutScreenInfo;

import javax.swing.*;
import java.awt.*;

/**
 * @author: zheng
 * @code date: 2022/10/11
 * @code className: ScreenFrame
 * @code description: 全屏截图容器类
 */
public class ScreenFrame {
    private JFrame frame = new JFrame();
    private CutScreenInfo cutScreenInfo = null;
    private ScreenPane canvas = null;

    public ScreenFrame(CutScreenInfo cutScreenInfo) {
        canvas = new ScreenPane(cutScreenInfo, this);
        this.cutScreenInfo = cutScreenInfo;
        getScreenJFrame();
        frame.setState(Frame.ICONIFIED);
        frame.setState(Frame.NORMAL);
    }


    /**
     * @method: 截取全屏画布，作为划取截屏的桌面
     */
    public JFrame getScreenJFrame() {
        //设置全屏图片
        Cursor cu = new Cursor(Cursor.CROSSHAIR_CURSOR);
        frame.setCursor(cu);

        frame.setContentPane(canvas);
        frame.setSize(ContainerSize.getContainerSize().getWindowWidth(), ContainerSize.getContainerSize().getWindowHeight());
        frame.setLocationRelativeTo(null);
        frame.setExtendedState(JFrame.MAXIMIZED_BOTH);;
        frame.setBounds(0, 0, ContainerSize.getContainerSize().getWindowWidth(), ContainerSize.getContainerSize().getWindowHeight());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setUndecorated(true);
        frame.setVisible(true);
        return frame;
    }

    public void distroy() {
        try {
            frame.setVisible(false);
            cutScreenInfo = null;
            frame = null;
            canvas = null;
            finalize();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
    }
}
